package com.geek.javase.wcy02;

import java.util.Scanner;

/**
 * @author wangchaoyang
 * @desc TODO
 * @date 2025/9/2
 */
public class ForDemo4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个整数：");
        int num = scanner.nextInt();
        // 处理特殊情况：输入为0直接输出
        if (num == 0) {
            System.out.println("倒排后的结果：0");
            scanner.close();
            return;
        }
        // 去除原数字末尾的零
        int temp = num;
        while (temp % 10 == 0) {
            temp /= 10;
        }
        // 反转处理后的数字（纯数学运算）
        int reversed = 0;
        while (temp != 0) {
            int lastDigit = temp % 10;
            reversed = reversed * 10 + lastDigit;
            temp /= 10;
        }
        System.out.println("倒排后的结果：" + reversed);
    }
}
